package com.zhu.ecology;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * Created by DELL on 2016/2/2.
 */
public class DaySign {
    public static final String SPLIT_STR = "-----------------------------------------------------------------------------------------------------------------------------------------";
    public static final String TITLE_DESC = "|\t星期\t|\t日期\t\t|\t签到时间\t|\t签退时间\t|\t签到IP\t\t|\t签退IP\t\t|";
    private static final String[] WEEK_DESC = new String[]{"星期六","星期天","星期一","星期二","星期三","星期四","星期五"};
    private String date;
    private int weekIndex;
    private String signInTime;
    private String signOutTime;
    private String signInIp;
    private String signOutIp;

    public DaySign(){}

    public DaySign(String date, String signInTime, String signOutTime, String signInIp, String signOutIp) {
        this.date = date;
        this.signInTime = signInTime;
        this.signOutTime = signOutTime;
        this.signInIp = signInIp;
        this.signOutIp = signOutIp;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getSignInTime() {
        return signInTime;
    }

    public void setSignInTime(String signInTime) {
        this.signInTime = signInTime;
    }

    public String getSignOutTime() {
        return signOutTime;
    }

    public void setSignOutTime(String signOutTime) {
        this.signOutTime = signOutTime;
    }

    public String getSignInIp() {
        return signInIp;
    }

    public void setSignInIp(String signInIp) {
        this.signInIp = signInIp;
    }

    public String getSignOutIp() {
        return signOutIp;
    }

    public void setSignOutIp(String signOutIp) {
        this.signOutIp = signOutIp;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("|");
        String weekDesc = "--";
        if(date != null) {
            Calendar cal = Calendar.getInstance();
            try {
                cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(date));
                weekDesc = WEEK_DESC[cal.get(Calendar.DAY_OF_WEEK)%7];
            } catch (ParseException e) {
            }
        }
        sb.append("\t" + weekDesc + "\t|");
        sb.append("\t" + date + "\t|");
        sb.append("\t" + signInTime + "\t|");
        sb.append("\t" + (signOutTime == null? "-------\t":signOutTime) + "\t|");
        sb.append("\t" + signInIp + "\t|");
        sb.append("\t" + (signOutIp == null? "-------\t":signOutIp) + "\t|");

        return sb.toString();
    }

    public static void main(String[] args){
        HttpClient httpClient =new HttpClient();

        List<Header> headers = new ArrayList<Header>();
        headers.add(new Header("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"));
        httpClient.getHostConfiguration().getParams().setParameter("http.default-headers", headers);

        PostMethod postMethod = new PostMethod("http://oc-test.ehsy.com/supplier/bidorder/queryUnBidOrderList");
        postMethod.addParameter("queryData", "{bidSupplierId:2617}");

        try {
            if (HttpStatus.SC_OK == httpClient.executeMethod(postMethod)) {
                System.out.println(postMethod.getResponseBodyAsString());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
